﻿using System.Diagnostics;
using KinonekoSoftware.ArkSpark.Core.Delegates;
using KinonekoSoftware.ArkSpark.Documents;
using KinonekoSoftware.ArkSpark.Documents.Primitives;
using KinonekoSoftware.ArkSpark.Runtimes;
using KinonekoSoftware.ArkSpark.Runtimes.Presenters;

namespace KinonekoSoftware.ArkSpark
{
    partial class ArkSpark
    {
        private HeadingTextPresenter CreateHeadingText(DocumentElement element)
        {
            Debug.Assert(element is HeadingText);

            //
            //
            var element2 = (HeadingText)element;
            var presenter = new HeadingTextPresenter(element2)
            {
                //
                //
                Bus = this,
            };


            return presenter;
        }


        private DocumentElementPresenter CreatePicture(DocumentElement element)
        {
            Debug.Assert(element is PictureElement);

            //
            //
            var element2 = (PictureElement)element;
            var presenter = new PicturePresenter(element2)
            {
                //
                //
                Bus = this,
            };


            return presenter;
        }

        public static HeadingText CreateHeadingText(string content, int level = 1)
        {
            return new HeadingText
            {
                Id      = GetID(),
                Content = content,
                Level   = level,
            };
        }

        public static PictureElement CreatePicture(string source, string content = null)
        {
            return new PictureElement
            {
                Id          = GetID(),
                Description = content,
                Source      = source,
            };
        }

        protected override void OnInitializeFactories(IDictionary<Type, DocumentElementPresenterFactory> mapper)
        {
            mapper.Add(typeof(HeadingText), CreateHeadingText);
            mapper.Add(typeof(PictureElement), CreatePicture);
        }
    }
}